package cn.wjzhang.middle.modules.qrCode.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.img.ImgUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.extra.qrcode.QrCodeUtil;
import cn.hutool.extra.qrcode.QrConfig;
import cn.wjzhang.core.annotation.AutoLog;
import cn.wjzhang.core.beans.vo.Result;
import cn.wjzhang.middle.beans.request.QrRequest;
import cn.wjzhang.middle.utils.QRCodeUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

/**
 * ========================
 * 功能描述
 *
 * @author wjzhang
 * @version v1.0
 * ========================
 * @date 2023/6/29 14:52
 */
@Slf4j
@Api(tags = "二维码")
@RestController
@RequestMapping("/v1/qrCode")
public class MidQRCodeController {

    @ApiOperation("二维码生成")
    @PostMapping("/qrCode")
    @AutoLog(value = "二维码生成")
    public Result<?> qrCode(@Validated @RequestBody QrRequest request, BindingResult bindingResult) {
        return Result.OK("操作成功", QRCodeUtil.generate(request));
    }

    @ApiOperation("二维码解析")
    @PostMapping("/deQrCode")
    @AutoLog(value = "二维码解析")
    public Result<?> deQrCode(@RequestParam("file") MultipartFile file) {
        return Result.OK("操作成功", QRCodeUtil.deQrCode(file));
    }
}
